-
Notifications
You must be signed in to change notification settings - Fork 671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ACP-77: Current validators API for SoV #3404
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org> Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com>
Signed-off-by: Ceyhun Onur <ceyhun.onur@avalabs.org>
Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org> Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com>
…hego into refactor-uptime-manager
…urrent-validators-api
snow/validators/traced_state.go
Outdated
ctx context.Context, | ||
subnetID ids.ID, | ||
) (map[ids.ID]*GetCurrentValidatorOutput, uint64, bool, error) { | ||
ctx, span := s.tracer.Start(ctx, s.getValidatorSetTag, oteltrace.WithAttributes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we fix this in this PR? Seems simple enough to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with the minor question on the protobuf
message Validator { | ||
bytes node_id = 1; | ||
uint64 weight = 2; | ||
bytes public_key = 3; | ||
} | ||
|
||
message CurrentValidator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly dumb question but is there a good reason for not adding new fields to the existing Validator
message instead of adding a new one? i.e. do we see the data returned by them becoming incompatible at some point? It seems like it should be compatible since protobuf fields are all optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would mean a breaking change. Changing Validator
would require changes to related functions + clients. I think if we want to we can deprecate old methods and types in favor of CurrentValidator
. @StephenButtolph
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just have a field of type Validator
in CurrentValidator
? then you don't need to copy the first three fields.
My main question with this also in conjunction with ava-labs/subnet-evm#1263, is whether there is a possibility that the SoV validator would share the same nodeID as the ones initially set? |
Both this API and Subnet-EVM relies on Validation ID rather than NodeID. The case where different Validation IDs mapped to same NodeID should already be handled by the state (here), so this API should not return duplicated ones. For the Subnet-EVM we first handle deletions when we handle the new set from P-Chain. It guarantees that we delete the uptime from the state, even if the same nodeID is being deleted + readded under different validationIDs in the same load period. After deletion we add new data with the same nodeID. See here |
…s/avalanchego into test-only-current-validators-api
uint64 weight = 2; | ||
bytes public_key = 3; | ||
uint64 start_time = 4; | ||
uint64 set_weight_nonce = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is set_weight_nonce
for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's the MinNonce
of L1 validators
IsSov: vdr.IsSoV, | ||
} | ||
if vdr.PublicKey != nil { | ||
// This is a performance optimization to avoid the cost of compression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serializing in compressed form is cheap. It is the de-compression that is expensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
literally copied from L73
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood.
Though I think that this comment is a bit misleading - what it's probably actually trying to say is that in order to avoid the expensive decompression in the client side, the server side is not compressing.
@@ -831,6 +833,64 @@ func (s *state) DeleteExpiry(entry ExpiryEntry) { | |||
s.expiryDiff.DeleteExpiry(entry) | |||
} | |||
|
|||
func (s *state) GetCurrentValidatorSet(ctx context.Context, subnetID ids.ID) (map[ids.ID]*validators.GetCurrentValidatorOutput, uint64, error) { | |||
result := make(map[ids.ID]*validators.GetCurrentValidatorOutput) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to check currentStakers
is not nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentStakers are initialized to be empty in New
This pull request introduces a new gRPC method
GetCurrentValidatorSet
to theValidatorState
service, allowing clients to retrieve the current validator set for a given subnet. The changes span multiple files to implement this new functionality, including updates to the protobuf definitions, client and server interfaces, and associated tests.Additions to
ValidatorState
Service:proto/pb/validatorstate/validator_state_grpc.pb.go
: Added theGetCurrentValidatorSet
method to both client and server interfaces, along with its handler and full method name constant. [1] [2] [3] [4] [5] [6] [7]proto/validatorstate/validator_state.proto
: Defined theGetCurrentValidatorSetRequest
andGetCurrentValidatorSetResponse
messages, and added the new RPC method to theValidatorState
service. [1] [2]Client and Server Implementation:
snow/validators/gvalidators/validator_state_client.go
: Implemented theGetCurrentValidatorSet
method in theClient
struct to call the new gRPC method.snow/validators/gvalidators/validator_state_server.go
: Implemented theGetCurrentValidatorSet
method in theServer
struct to handle incoming requests.State Interface and Mock Updates:
snow/validators/state.go
: Added theGetCurrentValidatorSet
method to theState
interface and implemented it in thelockedState
struct. [1] [2] [3]snow/validators/traced_state.go
: Added tracing support for theGetCurrentValidatorSet
method.snow/validators/validator.go
: Defined theGetCurrentValidatorOutput
struct to represent the current validator data.snow/validators/validatorsmock/state.go
: Added mock implementations for theGetCurrentValidatorSet
method.snow/validators/validatorstest/state.go
: Added test support for theGetCurrentValidatorSet
method. [1] [2]Platform VM State Changes:
vms/platformvm/state/state.go
: Added theGetCurrentValidatorSet
method to theState
interface and implemented it in thestate
struct, including logic to determine if the subnet is L1 and fetch the current validators. [1] [2]vms/platformvm/state/mock_state.go
: Added mock implementations for theGetCurrentValidatorSet
method.